package org.chengn.level_hard.context466;

/**
 * @Title: context466
 * @Author ChengN
 * @Package org.chengn.level_hard.context466
 * @Date 2024/1/2 23:59
 * @description: 统计重复个数——差点超时
 */
public class Context466 {
    public int getMaxRepetitions(String s1, int n1, String s2, int n2) {
        int idx1 = 0, idxn1 = 0, idx2 = 0, cycle = 0;
        int[] ans = new int[n1 + 1];
        while (idxn1 < n1) {
            while (idx1 < s1.length()) {
                if (s1.charAt(idx1++) != s2.charAt(idx2)) {
                    continue;
                }
                idx2 += 1;
                // System.out.println(idx2);
                cycle += idx2 / s2.length();
                idx2 = idx2 % s2.length();
            }
            idxn1++;
            idx1 = 0;
            ans[idxn1] = cycle;
            if (idx2 == 0) {
                // System.out.println(idxn1 + " " + cycle + " " + ans[n1 - n1 / idxn1 * idxn1]);
                return (n1 / idxn1 * cycle + ans[n1 - n1 / idxn1 * idxn1]) / n2;
            }
        }
        // System.out.println(cycle / n2);
        return cycle / n2;
    }
}
